package com.xyw.code.study202007281.processor;

import com.xyw.code.study202007281.handler.OrderHandler;
import com.xyw.code.study202007281.handler.OrderHandlerBO;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: xuyiwei
 * Date: 2020/7/29
 * Time: 上午9:12
 * Email: 1328312923@qq.com
 * Description: No Description
 **/
public class HandlerPayMethodContext {
    private Map<OrderHandlerBO, Class > handlerMap = new HashMap<>();

    public HandlerPayMethodContext(Map<OrderHandlerBO,  Class > handlerMap) {
        this.handlerMap = handlerMap;
    }

    public  OrderHandler getInstance(OrderHandlerBO bo) throws IllegalAccessException {
        Class clazz = handlerMap.get(bo);
        if(bo==null){
            throw new IllegalAccessException("not found handler for type:"+bo.toString());
        }
        return (OrderHandler) SpringContextUtils.getBean(clazz);

    }
}
